package com.ruoyi.task.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.task.domain.TaskDetail;
import com.ruoyi.task.service.ITaskDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务详情Controller
 * 
 * @author ruoyi
 * @date 2024-03-24
 */
@RestController
@RequestMapping("/task/detail")
public class TaskDetailController extends BaseController
{
    @Autowired
    private ITaskDetailService taskDetailService;

    /**
     * 查询任务详情列表
     */
    @PreAuthorize("@ss.hasPermi('task:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskDetail taskDetail)
    {
        startPage();
        List<TaskDetail> list = taskDetailService.selectTaskDetailList(taskDetail);
        return getDataTable(list);
    }

    /**
     * 导出任务详情列表
     */
    @PreAuthorize("@ss.hasPermi('task:detail:export')")
    @Log(title = "任务详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskDetail taskDetail)
    {
        List<TaskDetail> list = taskDetailService.selectTaskDetailList(taskDetail);
        ExcelUtil<TaskDetail> util = new ExcelUtil<TaskDetail>(TaskDetail.class);
        util.exportExcel(response, list, "任务详情数据");
    }

    /**
     * 获取任务详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('task:detail:query')")
    @GetMapping(value = "/{subtaskId}")
    public AjaxResult getInfo(@PathVariable("subtaskId") Integer subtaskId)
    {
        return success(taskDetailService.selectTaskDetailBySubtaskId(subtaskId));
    }

    /**
     * 新增任务详情
     */
    @PreAuthorize("@ss.hasPermi('task:detail:add')")
    @Log(title = "任务详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskDetail taskDetail)
    {
        return toAjax(taskDetailService.insertTaskDetail(taskDetail));
    }

    /**
     * 修改任务详情
     */
    @PreAuthorize("@ss.hasPermi('task:detail:edit')")
    @Log(title = "任务详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskDetail taskDetail)
    {
        return toAjax(taskDetailService.updateTaskDetail(taskDetail));
    }

    /**
     * 删除任务详情
     */
    @PreAuthorize("@ss.hasPermi('task:detail:remove')")
    @Log(title = "任务详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{subtaskIds}")
    public AjaxResult remove(@PathVariable Integer[] subtaskIds)
    {
        return toAjax(taskDetailService.deleteTaskDetailBySubtaskIds(subtaskIds));
    }
}
